package com.gx.gxreader.fragment

import android.support.v7.widget.GridLayoutManager
import com.gx.gxreader.R
import com.gx.gxreader.adapter.CommentAdapter
import com.gx.gxreader.base.BaseFragment
import com.gx.gxreader.presenter.ClassificationPresenter
import com.gx.gxreader.view.ClassificationView
import kotlinx.android.synthetic.main.fragment_classification.*
import kotlinx.android.synthetic.main.rcv_item_classification.view.*

/**
 * 分类：出版、独家、男生、女生、会员
 */
class ClassificationFragment : BaseFragment<ClassificationView, ClassificationPresenter>(), ClassificationView {
    override fun getContentViewId(): Int = R.layout.fragment_classification

    override fun createPresenter(): ClassificationPresenter = ClassificationPresenter()

    override fun initView() {
        rcvClassification.setHasFixedSize(true)
        rcvClassification.setNestedScrollingEnabled(false)
        rcvClassification.layoutManager = GridLayoutManager(activity, 2)
        rcvClassification.adapter = CommentAdapter.Builder()
                .setDatas(getData())
                .setLayoutId(R.layout.rcv_item_classification)
                .bindView(object : CommentAdapter.BindView{
                    override fun onBindView(viewHolder: CommentAdapter.MyViewHolder, data: Any?) {
                        val myData : String = data as String
                        viewHolder.itemView.tvClassificationName.text = myData
                    }
                }).create()
    }

    override fun initListener() {

    }

    /**
     * 制造假数据
     * 返回一个ArrayList<string> 的集合
     * */
    fun getData(): ArrayList<String> {
        val arrayList = ArrayList<String>()
        val list = listOf<String>("a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n", "o", "p")
        //for循环
        for (k in list) {
            arrayList.add(k)
        }
        return arrayList
    }
}